package day7;

import java.util.*;

public
class TestTreeSet {
    public static
    void main(String[] args) {
        //1.数字的TreeSet
        Set<Integer> set = new TreeSet<>(Arrays.asList(3, 7, 1, 2, 9, 5, 5, 4, 4));
        System.out.println(set);
        //2.String的TreeSet
        Set<String> set1 = new TreeSet<>(Arrays.asList("apple", "add", "banana", "pear"));
        System.out.println(set1);
        Set<String> set2 = new TreeSet<>((o1, o2) -> o2.compareTo(o1));
        set2.addAll(set1);
        System.out.println(set2);
        //对象的TreeSet
        Set<Card> set3 = new TreeSet<>();
        List<Card> list = new ArrayList<>();
        String[] c = {"♥", "♠", "♣", "♦"};
        String[] s = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "小王", "大王"};
        for (int i = 0; i < s.length; i++) {
            if (i < 13) {
                for (String s1 : c) {
                    list.add(new Card(s1 + s[i], i + 3));
                }
            }else {
                list.add(new Card(s[i], i + 3));
            }
        }
        System.out.println(list);
        Collections.shuffle(list);
    }
}
class Card{
    String str;//存储牌
    int num;//牌面数字
    public Card(String str,int num){
        this.str=str;
        this.num=num;
    }
    public String toString(){
        return str;
    }
}
//(o1, o2) -> {
//            int i=o2.num-o1.num;
//            //判断是否相同
//            if (i == 0) i=o1.str.compareTo(o2.str);
//            return i;
//        }